﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GeneralPriviledgeManagement
{
    public static class ControlExtension
    {
        public static IEnumerable<T> GetControls<T>(this Control control, Func<T, bool> filter) where T : Control
        {
            foreach (Control c in control.Controls)
            {
                if (c is T && (filter == null || filter(c as T)))
                {
                    yield return c as T;
                }
                foreach (T _t in GetControls<T>(c, filter))
                    yield return _t;
            }
        }

        public static IEnumerable<T> GetControls<T>(this Control control) where T : Control
        {
            return control.GetControls<T>(null);
        }


    }
}
